import java.util.Random;


public class Competition 
{
	private int groups;
	private int players;
	private int weightNum;
	
	private WeightCollection[] firstRoundWinnersWeights;
	
	private int[] winnersWeights;
	
	public Competition(int groups, int players, int numberOfWeights)
	{
		this.groups = groups;
		this.players = players;
		this.weightNum = numberOfWeights;
		
		winnersWeights = new int[numberOfWeights];
		
		firstRoundWinnersWeights = new WeightCollection[groups];
	}
	
	public void playFirstRound() throws Exception
	{
		for(int i = 0; i < groups; i++)
		{
			Group g = new Group(players, weightNum);
			g.createGroup();
			g.fightGroup();
			firstRoundWinnersWeights[i] = g.getWinnersWeights();
		}
	}
	
	public void averageWinnersWeights() throws Exception
	{
		int[] sumOfWeights = new int[weightNum];
		for(int i = 0; i < firstRoundWinnersWeights.length; i++)
		{
			for(int j = 0; j < weightNum; j++)
			{
				sumOfWeights[j] = sumOfWeights[j] + firstRoundWinnersWeights[i].getWeight(j);
			}
		}
		
		for(int i = 0; i < weightNum; i++)
		{
			sumOfWeights[i] = sumOfWeights[i]/firstRoundWinnersWeights.length;
			winnersWeights[i] = sumOfWeights[i];
		}
	}
	
	public int[] getWinnersWeights()
	{
		return winnersWeights;
	}
}
